<template>
  <f7-page name="commentPage" color-theme="red" class="backgroundColor">
    <div class="navbarCommentPage  page-content">
      <div class="navbar_l" @click="$f7router.back()">
        <f7-button>
          <svg-icon iconClass="horn_down_white" v-if="getThemeDark" />
          <svg-icon iconClass="horn_down" v-else />
        </f7-button>
      </div>
      <div class="navbar_m">
        <div class="mText">
          <span class="titleColor">评论区</span>
        </div>
      </div>
      <div class="navbar_r"></div>
    </div>
    <f7-block class="commentPage_commentBox">
      <v-comment :commentType="shareType" :shareId="shareId" @responseSomebody="responseSomebody" :key="components_key"/>
    </f7-block>
    <v-messageBar
      v-show="getBottomBarState"
      @messageBarBlur="handleBlur"
      @messageBarSend="handleMessageBarSend"
      ref="messageBarRef"
    />
  </f7-page>
</template>
<script>
import Comment from '@/components/comment.vue'
import MessageBar from '@/components/messagebar.vue'
import { mapGetters } from 'vuex'
import { addComment, } from '@/api/share.js'
export default {
  components: {
    'v-comment': Comment,
    'v-messageBar': MessageBar,
  },
  computed: {
    ...mapGetters({
      getBottomBarState: 'getBottomBarState',
      getThemeDark: 'getThemeDark',
      getUserInfo: 'getUserInfo',
    }),
  },

  props: {
    shareType: {
      type: String,
      default: '', //song,songList
    },
    shareId: {
      type: Number,
    },
  },
  data() {
    return {
      responseToParentId: 0,
      components_key:0,
    }
  },
  methods: {
    handleBlur(val) {
      if (!val) {
        this.responseToParentId = 0;
      }
    },
    handleMessageBarSend(val) {
      let queryData = {}
      if (this.shareType === 'song') {
        queryData = {
          sharedSongId: this.shareId,
          parentId: this.responseToParentId,
          userId: this.getUserInfo.userid,
          comment: val,
          userName:this.getUserInfo.userName,
        }
      } else {
        queryData = {
          sharedSongListId: this.shareId,
          parentId: this.responseToParentId,
          userId: this.getUserInfo.userid,
          comment: val,
          userName:this.getUserInfo.userName,
        }
      }

      addComment(queryData)
        .then((res) => {
          if (res.code === 200) {
            this.$f7ready((f7) => {
              var toastTop = f7.toast.create({
                text: '评论成功',
                position: 'top',
                closeTimeout: 1500,
              })
              toastTop.open()
              this.components_key++;
              this.$bus.$emit('updateHotComment',this.shareType,this.shareId)
            })
          }
        })
        .catch((err) => {
          console.log(err)
        })
    },
    responseSomebody(id){
      this.responseToParentId = id;
      this.$refs.messageBarRef.focusMessageBar();
    },
  },
}
</script>
<style lang="scss" scoped>
.navbarCommentPage {
  display: flex;
  align-items: center;
  height: 9vh;
  .navbar_l {
    width: 12vw;
    .svg-icon {
      width: 0.4rem;
      height: 0.4rem;
    }
  }
  .navbar_m {
    flex: 1;
    width: 72vw;
    margin-left: 1vw;
    span {
      font-size: 18px;
      white-space: nowrap;
    }
    .mText {
      width: 72vw;
    }
  }
}
.commentPage_commentBox {
  margin: 0;
  height: calc(91vh - var(--f7-toolbar-link-height, var(--f7-toolbar-height)));
  overflow-y:scroll;
}
</style>
